package com.teziyou.commodity.core.thrift;

import org.apache.thrift.transport.TTransport;

import com.teziyou.commodity.util.ThreadLocalUtil;

public class BaseConnectionManagerImpl {
	
	/**
	 * 获取socket
	 * @return TSocket
	 */
	public TTransport getTransport(ConnectionProvider connectionProvider) {
		TTransportBean tTransportBean = null;
		TTransport tTransport = null;
		try {
			tTransportBean = connectionProvider.getConnection();
			tTransport = tTransportBean.gettTransport();
			ThreadLocalUtil.put("thrift", tTransport);

			return (TTransport)ThreadLocalUtil.get("thrift");
		} catch (Exception e) {
			e.printStackTrace();
			throw new RuntimeException(e);
		} finally {
			connectionProvider.close(tTransportBean);
			ThreadLocalUtil.remove();
		}

	}

}
